package org.autoparser.exttree.termoper;

import org.autoparser.exttree.terms.ZAttrUsRegexTerm;
import org.autoparser.exttree.terms.ZAttributeTerm;
import org.autoparser.exttree.terms.ZExtractTerm;
import org.autoparser.exttree.terms.ZHtmlTerm;
import org.autoparser.exttree.terms.ZHtmlUsRegexTerm;
import org.autoparser.exttree.terms.ZTextTerm;
import org.autoparser.exttree.terms.ZTextUsRegexTerm;
import org.dom4j.Element;

class ZTermFactory {
	public static ZExtractTerm CreateTerm(Element e){
		String key = e.getName();
		ZExtractTerm term = null;
		if(key.compareToIgnoreCase("attribute") == 0){
			if(e.attributeValue("regex") != null)
				term = new ZAttrUsRegexTerm(e.attributeValue("columnName"),e.getText(),e.attributeValue("regex"));
			else
				term = new ZAttributeTerm(e.attributeValue("columnName"),e.getText());
		}
		else if(key.compareToIgnoreCase("text") == 0){
			if(e.attributeValue("regex") != null)
				term = new ZTextUsRegexTerm(e.attributeValue("columnName"),e.attributeValue("regex"));
			else
				term = new ZTextTerm(e.attributeValue("columnName"));
		}
		else if(key.compareToIgnoreCase("html") == 0){
			if(e.attributeValue("regex") != null)
				term = new ZHtmlUsRegexTerm(e.attributeValue("columnName"),e.attributeValue("regex"));
			else
				term = new ZHtmlTerm(e.attributeValue("columnName"));
		}
		return term;
	}
}
